import { appGetStorage } from "@/utils/storage";
import { USER_LOCATION_KEY, USER_CURRENT_LOCATION_KEY } from "@/utils/location";
import { appSetStorage } from "@/utils/storage";

const state = {
  /*
   * 参数：
   * latitude: 0 --坐标
   * longitude: 0 --坐标
   * address: ‘’ --地址
   * title:'' -- 坐标名
   * _distance:0 -- 距离
   * address_info:'' -- 省市区
   * */
  currentLocation:
    appGetStorage(USER_CURRENT_LOCATION_KEY) ||
    appGetStorage(USER_LOCATION_KEY), //选择的地址，首次加载是用户的地理位置，后面是选择的位置
};

const mutations = {
  SET_CURRENT_LOCATION: (state, val) => {
    state.currentLocation = val;
  },
};
const actions = {
  async setCurrentLocation({ commit }, data) {
    appSetStorage(USER_CURRENT_LOCATION_KEY, data);
    commit("SET_CURRENT_LOCATION", data);
  },
};
const getters = {};

export default {
  namespaced: true,
  actions,
  state,
  getters,
  mutations,
};
